home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 1.9 KB | 61 lines | [TEXT/ttxt] |
- --<<<
- -- Kaleida Labs, Inc.
- -- Field Guide to the ScriptX Language
- -- chapter 4, example 4
-
- -- for loop examples with collect or select
-
- -- create a module to be sure that names used here do not
- -- conflict with names used previously
- module Scratch16 uses ScriptX end
- in module Scratch16
-
- -- declare globals
- global firstArray, secondArray, thirdArray, bigJumbledArray, \
- niceNeatArray, sinvals, negativesins, status, i, squares, s, \
- nums, doors, openDoors, reagan, speech
-
- for i := 1 to 10 collect i
- global sinvals := for i := 1 to 3 collect sin i
- global negativesins := for i := 1 to 10 select (sin i) if (sin i) < 0
-
- global status := #(@doorClosed:false, @keyInIgnition:true,
- @propellerMoving:true)
- print status
-
- for i in #(@doorClosed, @keyInIgnition, @propellerMoving)
- select i if status[i] = true
-
- global squares := #()
- for s in 1 to 10 collect into squares (s * s)
-
- nums := for i in 1 to 5 collect i
- for i in 20 to 23 collect into nums i
- for i in 40 to 45 collect into nums i
-
- global doors, openDoors := #()
- doors := #(@front:false,@back:true,@side:true,@garage:false)
- for i in #(@front,@back,@side,@garage)
- select i into openDoors if doors[i] = true
-
- global firstArray := #(1,2,3,4,5)
- global secondArray := #(@yes,@no,@maybe)
- global thirdArray := #("sow","ewe","cow","hen")
- bigJumbledArray := #(firstArray,secondArray,thirdArray)
- niceNeatArray := #()
- for i in bigJumbledArray collect into niceNeatArray by merge i
-
- global reagan := new String string:""
- speech := "Facts are stupid things"
- -- define a function that can act as a collector or selector
- function prependReturningSelf sequence value -> (
- prepend sequence value
- return sequence
- )
- -- use the collector function to reverse the string
- for i in speech collect into reagan by prependReturningSelf i
-
- -- as clause in a for loop
- for i in "jabberwocky" collect as Array i
- for i in "jabberwocky" select i as String if i > 105
- -->>>